<template>
  <!-- 排序区域 -->
  <div class='sub-sort'>
    <div class="sort">
      <a href="javascript:;"
      @click="setSort(sort.id)"
      :class="{active:currSelectedId===sort.id}"
      v-for="sort in sortList"
      :key="sort.id"
      >{{sort.name}}</a>
      <!-- <a href="javascript:;">最新商品</a>
      <a href="javascript:;">最高人气</a>
      <a href="javascript:;">评论最多</a> -->
    </div>
    </div>
</template>
<script>
import { ref, inject } from 'vue'
export default {
  name: 'SubSort',
  setup () {
    const sortList = ref([
      { id: null, name: '默认排序' },
      { id: 'publishTime', name: '最新商品' },
      { id: 'orderNum', name: '最高人气' },
      { id: 'evaluateNum', name: '评论最多' }
    ])
    const currSelectedId = ref(null)
    const filterParams = inject('filterParams')

    const setSort = (currSortId) => {
      if (currSelectedId.value === currSortId) return
      // 存储当前选择的条件=>目的=》发请求刷新列表
      filterParams.value.sortField = currSortId
      currSelectedId.value = currSortId
    }

    return { sortList, currSelectedId, setSort }
  }
}
</script>
<style scoped lang='less'>
.sub-sort {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .sort {
    display: flex;
    a {
      height: 30px;
      line-height: 28px;
      border: 1px solid #e4e4e4;
      padding: 0 20px;
      margin-right: 20px;
      color: #999;
      border-radius: 2px;
      position: relative;
      transition: all .3s;
      &.active {
        background: @xtxColor;
        border-color: @xtxColor;
        color: #fff;
      }
      .arrow {
        position: absolute;
        border: 5px solid transparent;
        right: 8px;
        &.up {
          top: 3px;
          border-bottom-color: #bbb;
            &.active {
            border-bottom-color: @xtxColor;
          }
        }
        &.down {
          top: 15px;
          border-top-color: #bbb;
          &.active {
            border-top-color: @xtxColor;
          }
        }
      }
    }
  }
  .check {
    .xtx-checkbox {
      margin-left: 20px;
      color: #999;
    }
  }
}
.list-container{
  margin-top: 20px;
  padding: 0 20px;
  background: #fff;
}
</style>
